import java.util.List;

public class Solution {
    //移动零
    public void moveZeroes(int[] nums) {
        int left = 0;
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            if (nums[i] != 0) {
                int flag = nums[left];
                nums[left++] = nums[i];
                nums[i] = flag;
            }
        }
    }

    //盛最多水的容器
    //第一种时间复杂度O(N2)
    public int maxArea1(int[] height) {
        int tmp = 0;
        int max = 0;
        int n = height.length;
        for (int i = 0; i < n; i++) {
            int flag = 1;
            for (int j = i + 1; j < n; j++) {
                if (height[j] <= height[i]) {
                    tmp = height[j] * flag;
                } else {
                    tmp = height[i] * flag;
                }
                if (tmp > max) {
                    max = tmp;
                }
                flag++;
            }
        }
        return max;

    }
    public int maxArea(int[] height) {
        int left=0;
        int right=height.length-1;
        int max=0;
        while(left<right){
            if(height[left]<height[right]){
                max=Math.max(max,height[left]*(right-left));
                left++;
            }else{
                max=Math.max(max,height[right]*(right-left));
                right--;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] array={1,8,6,2,5,4,8,3,7};
        System.out.println(solution.maxArea(array));
    }
}
